<?php  

/** 
* Assets page (Controller) 
* Страница активов (контроллер) 
* @author IT studio IRBIS-team 
* @copyright © 2009 IRBIS-team 
*/
/////////////////////////////////////////////////////////

/**
* Generation of page of an error at access out of system
* Генерация страницы ошибки при доступе вне системы
*/
    if(!defined('IRB_KEY'))
    {
       header("HTTP/1.1 404 Not Found");      
       exit(file_get_contents('../../404.html'));
    } 
//////////////////////////////////////////////////////////

/**
* We connect a file of the MySQL functions
* Подключаем файл функций MySQL
*/  
   include './libs/mysql.php'; 
      

	$query_assets = mysqlQuery("SELECT 	DISTINCT a.id as asset_id,
										a.caption as asset_caption,
										d.id as dom_id,
										d.caption as dom_caption,
										u.name as user_name,
										u.surname as user_surname
								FROM 	
										`". IRB_DBPREFIX ."assets` a,
										`". IRB_DBPREFIX ."user` u,
										`". IRB_DBPREFIX ."domains` d,
										`". IRB_DBPREFIX ."asset_link_dom_user` aldu,
										`". IRB_DBPREFIX ."dom_link_user` dlu
								WHERE	dlu.user_id = '".(int)$_SESSION['user_data']['id']."'
								AND		dlu.domain_id = aldu.dom_id
								AND		u.id = a.owner
								AND		d.id = 	aldu.dom_id
								AND		a.id = aldu.asset_id
								");
	
	if(mysql_num_rows($query_assets) > 0)
		{
			$d_assets = array();
			while ($row_d = mysql_fetch_assoc($query_assets)) 
				$d_assets[$row_d['dom_caption']][] = $row_d;
		}
	
	$query_tags = mysqlQuery("SELECT DISTINCT at.id, at.caption
								FROM `". IRB_DBPREFIX ."assets_tags` at, 
									`". IRB_DBPREFIX ."asset_link_tag` alt, 
									`". IRB_DBPREFIX ."asset_link_dom_user` aldu, 
									`". IRB_DBPREFIX ."dom_link_user` dlu
								WHERE dlu.user_id = '".(int)$_SESSION['user_data']['id']."'
								AND dlu.domain_id = aldu.dom_id
								AND aldu.asset_id = alt.asset_id
								AND	alt.tag_id = at.id
								");
	
	if(mysql_num_rows($query_tags) > 0)
		{
			$tags = array();
			while ($row_t = mysql_fetch_assoc($query_tags)) 
				$tags[] = $row_t;
		}
